package com.ssy.jt808.gateway.infrastructure.enums;

import com.ssy.jt808.gateway.domain.pojo.TerminalInfo;
import com.ssy.netmc.session.Session;

import java.util.Objects;

/**
 * @author yezhihao
 * https://gitee.com/yezhihao/jt808-server
 */
public enum SessionAttribute{

  /** 终端信息 */
  TerminalInfo;

  public static TerminalInfo doGetTerminalInfo( Session session ){

    TerminalInfo terminalInfo = (TerminalInfo)session.getAttribute(TerminalInfo);
    if( Objects.isNull(terminalInfo) ){
      terminalInfo = new TerminalInfo();
      session.setAttribute(TerminalInfo, terminalInfo);
    }

    return terminalInfo;
  }

  public static void setTerminalInfo( Session session, TerminalInfo terminalInfo ){
    session.setAttribute(TerminalInfo, terminalInfo);
  }
}